package com.kzw.oa.comm.sorter;

import java.util.Comparator;

import com.kzw.oa.model.system.AppUser;

@SuppressWarnings("rawtypes")
public class AppUserSorter implements Comparator {

	@Override
	public int compare(Object o1, Object o2) {

		if (o1.getClass() == AppUser.class && o2.getClass() == AppUser.class) {
			AppUser u1 = (AppUser) o1;
			AppUser u2 = (AppUser) o2;
			if (u1.getOrgSn() != null && u2.getOrgSn() != null) {
				int x1 = u1.getOrgSn().compareTo(u2.getOrgSn());
				if (x1 != 0)
					return x1;
			}
			if (u1.getUserSn() != null && u2.getUserSn() != null) {
				int x2 = u1.getUserSn().compareTo(u2.getUserSn());
				if (x2 != 0)
					return x2;
			}
			return u1.getUserId().compareTo(u2.getUserId());
		}

		if (o1.getClass() == Long.class && o2.getClass() == Long.class) {
			Long l1 = (Long) o1;
			Long l2 = (Long) o2;
			return l1.compareTo(l2);
		}

		if (o1.getClass() == Long.class) {
			return 1;
		} else {
			return -1;
		}
	}

}
